package ru.spb.osll.myfit.common;

import com.google.gwt.user.client.rpc.IsSerializable;

import java.util.*;

public class Page implements IsSerializable {

  private static final long serialVersionUID = -8642682637800639769L;

  private Vector<PageElement> m_elements = new Vector<PageElement>();
  private HashMap<String, String> m_parentVariables = new HashMap<String, String>();
  private Set<PageTag> m_tags = new TreeSet<PageTag>();

  public Page() {
  }

  public Vector<PageElement> getElements() {
    return m_elements;
  }

  public int countPageElements() {
    return m_elements.size();
  }

  public boolean hasElements() {
    return (m_elements != null && m_elements.size() > 0);
  }

  public void deleteElements() {
    m_elements.clear();
  }

  public void insertElement(PageElement element, int index) {
    m_elements.insertElementAt(element, index);
  }

  public void insert(PageElement element) {
    m_elements.add(element);
  }

  public PageElement getElement(int i) {
    return m_elements.get(i);
  }

  public HashMap<String, String> getParentVariables() {
    return m_parentVariables;
  }

  public void setParentVariables(HashMap<String, String> variables) {
    m_parentVariables = variables;
  }

  public void addParentVariables(HashMap<String, String> variables) {
    m_parentVariables.putAll(variables);
  }

  public Set<PageTag> getTags() {
    return Collections.unmodifiableSet(m_tags);
  }

  public void setTags(Set<PageTag> tags) {
    m_tags.clear();
    m_tags.addAll(tags);
  }

  public boolean containsTags(Set<PageTag> tags) {
    return m_tags.containsAll(tags);
  }
}
